#include"processbar.h"
#include<string.h>
#include<unistd.h>
#define N 101
#define STYLE '#'


void FlushProcess(double current,double total)
{
    char buffer[N];
    memset(buffer,0,sizeof(buffer));
    static int cnt = 0;
    const char* flag = "|/-\\";
    // 先填充#
    int num =(int) (current * 100 / total); 
    for(int i = 0; i < num; ++i)
    {
        buffer[i] = STYLE;
    }
    printf("[%-100s][%.2lf%%][%c]\r",buffer,(current * 100 / total),flag[cnt++ % 4]);
    fflush(stdout);
}
void process_v1()
{
    char buffer[N];
    memset(buffer,0,sizeof(buffer));
    int cnt = 0;
    const char* flag = "|/-\\";
    while(cnt <= 100)
    {
        printf("[%-100s] [%d%%] [%c]\r",buffer,cnt,flag[cnt % 4]);
        fflush(stdout);
        buffer[cnt++] = STYLE;
        usleep(50000);
    }
    printf("\n");
}
